package com.caigou.servlet;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jiliang.purchase.demo.think_liebiao;
import jiliang.purchase.demo.think_lingxing;
import jiliang.purchase.demo.think_shenhe;

import com.caigou.service.checkApplyService;

public class checkApplyServlet extends HttpServlet{
	
	/*
	 * 业务处理->查看申请
	 * 
	 * **/

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	private checkApplyService CKS = new checkApplyService();
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		//通过bh(编号查看信息)
		String bh = request.getParameter("bh");
		String sign = request.getParameter("sign");
		//System.out.println("sign"+sign);
		
		think_lingxing tlx = new think_lingxing();
		tlx = CKS.getLingXing(bh);
		List<think_liebiao> list = new ArrayList<think_liebiao>();
		list = CKS.getLieBiao(tlx.getSq_id());
		List<think_shenhe> list1 = new ArrayList<think_shenhe>();
		list1 = CKS.getShenHe(tlx.getSq_id());
		
		////System.out.println(getTime(tlx.getEditsj()));
		
		request.setAttribute("time", getTime(tlx.getEditsj()));
		request.setAttribute("lingxing", tlx);
		request.setAttribute("liebiao", list);
		request.setAttribute("shenhe", list1);
		request.setAttribute("sign", sign);
		
		request.getRequestDispatcher("checkForm.jsp").forward(request, response);
		
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
			doGet(request,response);
	}
	
	public String getTime(long interval)
	{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		  Date beginTime = null;
		try {
			beginTime = sdf.parse("1970-01-01 12:53:30");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		  //System.out.println(interval);
		  long l = (beginTime.getTime()+interval*1000);
		//  //System.out.println(sdf.format(l));
		
		return sdf.format(l);
	}

}
